home *** CD-ROM | disk | FTP | other *** search
/ APDL Other Worlds / APDL Other Worlds Collection.iso / SF3000 / Extras / !FednetCmp / c / FNCIconbar next >
Encoding:
Text File  |  2003-10-16  |  5.4 KB  |  178 lines

  1. /*
  2.  *  FednetCmp - Fednet file compression/decompression
  3.  *  Iconbar icon
  4.  *  Copyright (C) 2001  Chris Bazley
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public Licence as published by
  8.  *  the Free Software Foundation; either version 2 of the Licence, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public Licence for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public Licence
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /* ANSI library files */
  22. #include <stdlib.h>
  23. #include <stdbool.h>
  24. #include <string.h>
  25. #ifdef DEBUG
  26. #include <stdio.h>
  27. #endif
  28.  
  29. /* RISC OS library files */
  30. #include "kernel.h"
  31. #include "toolbox.h"
  32. #include "event.h"
  33. #include "iconbar.h"
  34. #ifdef DEBUG
  35. #include "flex.h"
  36. #endif
  37.  
  38. /* My library files */
  39. #include "err.h"
  40. #include "msgtrans.h"
  41. #include "Macros.h"
  42. #include "Loader.h"
  43. #include "ViewsMenu.h"
  44. #include "hourglass.h"
  45.  
  46. /* Local headers */
  47. #include "Main.h"
  48. #include "Utils.h"
  49. #include "SaveFile.h"
  50. #include "SaveDir.h"
  51. #include "FNCIconbar.h"
  52.  
  53. static ObjectId Iconbar_id = NULL_ObjectId;
  54.  
  55. /* ----------------------------------------------------------------------- */
  56. /*                       Function prototypes                               */
  57.  
  58. static ToolboxEventHandler _Iconbar_clickhandler;
  59. static LoaderFinishedHandler _Iconbar_filedrophandler, _Iconbar_dirdrophandler;
  60.  
  61. /* ----------------------------------------------------------------------- */
  62. /*                         Public functions                                */
  63.  
  64. void Iconbar_initialise(ObjectId id)
  65. {
  66.   Iconbar_id = id;
  67.  
  68.   /* Register listeners for files dropped on iconbar icon */
  69.   EF(loader_register_listener(0, FILETYPE_ALL, id, NULL, load_plain, _Iconbar_filedrophandler, (void *)1));
  70.   for(int i = 0; i < sizeof(fednet_filetypes)/sizeof(int); i++) {
  71.     EF(loader_register_listener(0, fednet_filetypes[i], id, NULL, load_compressed, _Iconbar_filedrophandler, (void *)0));
  72.   }
  73.   EF(loader_register_listener(LISTENER_FILEONLY, FILETYPE_DIR, id, NULL, NULL, _Iconbar_dirdrophandler, NULL));
  74.   EF(loader_register_listener(LISTENER_FILEONLY, FILETYPE_APP, id, NULL, NULL, _Iconbar_dirdrophandler, NULL));
  75.  
  76.   /* Listen for mouse clicks */
  77.   EF(event_register_toolbox_handler(id, Iconbar_Clicked, _Iconbar_clickhandler, NULL));
  78. }
  79.  
  80. /* ----------------------------------------------------------------------- */
  81. /*                         Private functions                               */
  82.  
  83. static int _Iconbar_clickhandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
  84. {
  85. #ifdef DEBUG
  86.   int keypressed = _kernel_osbyte(129, (0^0xff), 0xff);
  87.   /* Check whether SHIFT held */
  88.   if(keypressed == _kernel_ERROR) {
  89.     _kernel_oserror *err = _kernel_last_oserror();
  90.     err_complain(err->errnum, err->errmess);
  91.     return 1;
  92.   }
  93.   if((keypressed & 0xff) == 0xff) {
  94.     char string[255];
  95.     int prev = flex_set_budge(1);
  96.     sprintf(string, "report Budge state = %d", prev);
  97.     flex_set_budge(prev);
  98.     _kernel_oscli(string);
  99.   }
  100.   else
  101. #endif
  102.     /* bring all open windows to front */
  103.     RE(ViewsMenu_showall())
  104.  
  105.   return 1; /* claim event */
  106. }
  107.  
  108. /* ----------------------------------------------------------------------- */
  109.  
  110. static void _Iconbar_filedrophandler(char *file_path, bool data_saved, flex_ptr buffer, int filetype, void *handle)
  111. {
  112.   /* setting of 'handle' indicates compress(1) or decompress(0) file */
  113.   ObjectId oldbox, newbox;
  114.  
  115.   /* Check for existing dialogues */
  116.   if(!multi_saveboxes)
  117.     oldbox = last_savebox;
  118.   else {
  119.     if(data_saved)
  120.       oldbox = ViewsMenu_findview(file_path);
  121.     else
  122.       oldbox = NULL_ObjectId;
  123.   }
  124.  
  125.   /* Create save dialogue */
  126.   newbox = SaveFile_create(file_path, data_saved, buffer, (int)handle);
  127.   if(newbox == NULL_ObjectId) {
  128.     flex_free(buffer);
  129.     return;
  130.   }
  131.  
  132.   /* Open save dialogue */
  133.   if(E(open_above_iconbar(0, newbox, Iconbar_id, NULL_ComponentId))) {
  134.     /* Oh dear, new dialogue window won't open  */
  135.     RE(toolbox_delete_object(0, newbox))
  136.   }
  137.   else {
  138.     last_savebox = newbox;
  139.     /* Remove any old savebox (same filepath or only one at a time allowed) */
  140.     if(oldbox != NULL_ObjectId)
  141.       RE(toolbox_hide_object(0, oldbox)) /* will delete self when ready */
  142.   }
  143. }
  144.  
  145. /* ----------------------------------------------------------------------- */
  146.  
  147. static void _Iconbar_dirdrophandler(char *file_path, bool data_saved, flex_ptr buffer, int filetype, void *handle)
  148. {
  149.   ObjectId oldbox, newbox;
  150.  
  151.   /* Check for existing dialogues */
  152.   if(!multi_saveboxes)
  153.     oldbox = last_savebox;
  154.   else {
  155.     if(data_saved)
  156.       oldbox = ViewsMenu_findview(file_path);
  157.     else
  158.       oldbox = NULL_ObjectId;
  159.   }
  160.  
  161.   /* Create an output dialogue for a new batch operation */
  162.   newbox = SaveDir_create(file_path);
  163.   if(newbox == NULL_ObjectId)
  164.     return;
  165.  
  166.   /* Open save dialogue */
  167.   if(E(open_above_iconbar(0, newbox, Iconbar_id, NULL_ComponentId))) {
  168.     /* Oh dear, new dialogue window won't open  */
  169.     RE(toolbox_delete_object(0, newbox))
  170.   }
  171.   else {
  172.     last_savebox = newbox;
  173.     /* Remove any old savebox (same filepath or only one at a time allowed) */
  174.     if(oldbox != NULL_ObjectId)
  175.       RE(toolbox_hide_object(0, oldbox)) /* will delete self when ready */
  176.   }
  177. }
  178.